namespace Billing
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class ucForgotPassword : UserControl
    {
        protected UpdatePanel ActionPanel;
        protected Button btnSend;
        protected Panel PanelDetails;
        protected TextBox txtUserName;
        protected ucHighlight ucHighlight1;
        protected UpdatePanel updatePanel3;
        protected UpdateProgress UpdateProgress1;

        protected void btnSend_Click(object sender, EventArgs e)
        {
            if (this.txtUserName.Text.Trim() == "")
            {
                this.ucHighlight1.ErrorMessage = "Unable to find your user name";
            }
            else
            {
                ClsUserProfile clsProfile = new ClsUserProfile {
                    LoginId = this.txtUserName.Text
                };
                DataTable dt = clsProfile.SelectByLoginID();
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        clsProfile.LoginPassword = ClsPasswordHelper.Encrypt(ClsPasswordHelper.Generate(8, 2, 1));
                        clsProfile.UpdateByLoginIdForPassword();
                        ClsEmailHelper cls = new ClsEmailHelper();
                        ClsEmailTemplate clsTemplate = new ClsEmailTemplate();
                        cls.IsBodyHtml = true;
                        clsTemplate.ResetPassword(clsProfile.LoginId, ClsPasswordHelper.Decrypt(clsProfile.LoginPassword));
                        cls.MailToAdd(dt.Rows[0]["Email"].ToString());
                        cls.Subject = clsTemplate.Subject;
                        cls.Body0 = clsTemplate.Body0;
                        string Msg = cls.SendEmail();
                        if (Msg.ToLower().Contains("fail"))
                        {
                            this.ucHighlight1.ErrorMessage = Msg;
                        }
                        else
                        {
                            this.ucHighlight1.Message = Msg;
                        }
                    }
                    else
                    {
                        this.ucHighlight1.ErrorMessage = "Unable to find your user name";
                    }
                }
                else
                {
                    this.ucHighlight1.ErrorMessage = "Unable to find your user name";
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.ucHighlight1.CloseAll();
        }
    }
}
